package com.tedsoft.first_group_project;

import java.util.List;

import com.tedsoft.framework.Color;
import com.tedsoft.framework.Game;
import com.tedsoft.framework.Graphics;
import com.tedsoft.framework.Input.TouchEvent;
import com.tedsoft.framework.Screen;

public class SplashScreen extends Screen {
    public SplashScreen(Game game) {
        super(game);               
    }   

    @Override
    public void update(float deltaTime) {
    	Graphics g = game.getGraphics();
           	
        List<TouchEvent> touchEvents = game.getInput().getTouchEvents();
        game.getInput().getKeyEvents();       
        
        int len = touchEvents.size();
        for(int i = 0; i < len; i++) {
            TouchEvent event = touchEvents.get(i);
            if(event.type == TouchEvent.TOUCH_DOWN && event.y>40) {
            	if(Settings.soundEnabled){
            	Assets.start.play(1);}
            	try {
					Thread.sleep(1000);
				} catch (InterruptedException e) {
					// przerwa na dzwiek, try i catch dodane automatycznie
					e.printStackTrace();
				}
            	
            	Settings.accel_Y_calibration_val = game.getInput().getAccelY();	
            	           	
            	game.setScreen(new MainGameScreen(game));
            	
                   	
            	return;
            	
            }
            if(event.type == TouchEvent.TOUCH_DOWN && event.x > g.getWidth()-40 && event.y < 40){
            	Settings.soundEnabled = !Settings.soundEnabled;	 //guzik mute
            }
            
        }
                
               
            
        
        
    }
    /*
    private boolean inBounds(TouchEvent event, int x, int y, int width, int height) {
        if(event.x > x && event.x < x + width - 1 && 
           event.y > y && event.y < y + height - 1) 
            return true;
        else
            return false;
    }
    */

    @Override
    public void present(float deltaTime) {
        Graphics g = game.getGraphics();
        g.drawPixmap(Assets.logoscreen, 0, 0);
        if(Settings.soundEnabled)
            g.drawPixmap(Assets.buttons, g.getWidth()-40, 0, 0, 0, 40, 40);
        else
        	g.drawPixmap(Assets.buttons, g.getWidth()-40, 0, 40, 0, 40, 40);
        //g.drawPixmap(Assets.tapthescreentocontinue, 27, 198);
           
    }

    @Override
    public void pause() {        
    
    }

    @Override
    public void resume() {

    }

    @Override
    public void dispose() {
    	
    }
}
